package com.rookie.data.generate.component;

import com.rookie.data.generate.component.generate.CommonTypeGenerate;
import com.rookie.data.generate.component.generate.ConstCollectionGenerate;
import com.rookie.data.generate.constant.annotation.CommonType;
import com.rookie.data.generate.constant.annotation.ConstCollection;
import com.rookie.data.generate.mapper.SystemMapper;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;

/**
 * spring 加载所有后需要处理的操作
 *
 * @author rookie
 */
@Component
public class LoadedAfterProcessBean implements SmartInitializingSingleton {

    @Autowired
    private Map<String, AbstractAnnotationGenerate> generateMap;

    @Resource
    private SystemMapper systemMapper;

    @Override
    public void afterSingletonsInstantiated() {
//        保证自定义的生成器中的依赖注入不会失效
        generateMap.forEach((v1, v2) -> {
            BeanContainer.generateAnnotation.put(v2.getAnnotationClass(), v2);
        });

        BeanContainer.SqlStringMaxSize = systemMapper.getSqlStringMaxSize().getValue();
    }
}
